package com.caigou.controller.front;

import com.caigou.bean.cms.param.ArticlePromoterParam;
import com.caigou.enums.ResponseEnum;
import com.caigou.service.ArticlePromoterService;
import com.caigou.service.ArticleService;
import com.caigou.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/front/articlePromoter/")
public class FrontArticlePromoterController {

    
    @Resource
    private ArticlePromoterService articlePromoterService;

    @Resource
    private ArticleService articleService;

    @RequestMapping("getArticlePromoter")
    public Result getArticlePromoter(@RequestBody ArticlePromoterParam articlePromoterParam){
        if(articlePromoterParam.getArticlePromoterId()==null){
            return Result.error(ResponseEnum.PARAM_ERROR);
        }
        return articlePromoterService.getArticlePromoterByArticlePromoterId(articlePromoterParam.getArticlePromoterId());
    }

    //获取作者的更多文章，支持分页
    @RequestMapping("listArticleByArticlePromoter")
    public Result listArticleByArticlePromoter(@RequestBody ArticlePromoterParam param){
        if(param.getArticlePromoterId()==null){
            return Result.error(ResponseEnum.PARAM_ERROR);
        }
        if(param.getPageNum()==null){
            param.setPageNum(1);
        }
        if(param.getPageSize()==null){
            param.setPageSize(10);
        }
        return articleService.listArticleByArticlePromoter(param.getArticlePromoterId(), param.getPageNum(), param.getPageSize());
    }

}
